package org.nf.dao.impl;

import org.nf.dao.UserAllDao;
import org.nf.dao.UserDao;
import org.nf.dbutil.DbUtil;
import org.nf.entity.User;
import org.nf.utils.SqlRunner;

import java.sql.Connection;
import java.util.List;

/**
 * @Author lzp
 * @Date 2024-04-25
 */
public class UserAllDaoImpl implements UserAllDao {
    @Override
    public List<User> userAll() {
        //第一 定义sql语句
        String sql = "SELECT `id`,`username`,`password`," +
                "`level`,`image`,`phone`,`email`,`registerTime`,`status` FROM user";

        // 第二：获取连接对象 实例化 SqlRunner 对象
        Connection conn = DbUtil.getConnection();
        SqlRunner sqlRunner = new SqlRunner(conn);

        //执行sql
        List<User> list = sqlRunner.query(User.class, sql);

        return list;
    }

    public static void main(String[] args) {
        UserAllDao userDao = new UserAllDaoImpl();
        List<User> list = userDao.userAll();
        list.forEach(System.out::println);


    }
}
